#!D:/CODE/python
# -*- coding: utf-8 -*-
# @Time : 2020/5/20 23:17
# @Author : Alexdong
# @Site : 
# @File : 文件下载器_客户端.py
# @Software: PyCharm
# Functional description:

from socket import *

def main():
    tcp_client_socket = socket(AF_INET, SOCK_STREAM)
    # 目的信息
    server_ip = input("请输入服务器ip:")
    server_port = input("请输入端口号：")
    # 链接服务器
    tcp_client_socket.connect((server_ip, server_port))

    # 提示用户输入信息：
    file_name = input("请输入要下载的文件名：")
    tcp_client_socket.send(file_name.encode("utf-8"))
    recv_data = tcp_client_socket.recv(1024)

    if recv_data:
        with open("[接收]"+file_name, 'wb') as f:
            f.write(recv_data)

    # 关闭套接字
    tcp_client_socket.close()

if __name__ == "__main__":
    main()